package gui;

import dao.*;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;
import pojo.*;
import java.util.List;
import javax.swing.JOptionPane;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmQuanLyChuoiCuaHang.java
 *
 * Created on Aug 22, 2012, 3:11:29 PM
 * 
 * @author dtth
 * Tên: Nguyễn Thị Ngọc Cẩm 
 * Lớp: 11HCB
 * MSSV: 1142006
 * 
 */
public class frmQuanLyChuoiCuaHang extends javax.swing.JFrame {

    private int _irow;
    private List<Cuahang> _lch;
    //day du lieu vao table
    
    
    public frmQuanLyChuoiCuaHang() {
        initComponents();
        this._irow = 0;
        this._lch = CuaHangDAO.layDanhSachCuaHang();
        fillJTable(this._lch);
    }

    public void hienThiDanhSachCuaHang() {
        DefaultTableModel TableModel;
        Vector rowHeader = new Vector();
        rowHeader.addElement("Tên Cửa Hàng");
        rowHeader.addElement("Tên Quản Lý");
        rowHeader.addElement("Địa Chỉ");
        rowHeader.addElement("Số ĐT");
        TableModel = new DefaultTableModel(rowHeader, 0);
        List<Cuahang> lsch = CuaHangDAO.layDanhSachCuaHang();

        for (int i = 0; i < lsch.size(); i++) {
            Cuahang ch = lsch.get(i);

            TableModel.setValueAt(ch.getTencuahang(), i, 0);
            TableModel.setValueAt(ch.getChucuahang(), i, 1);
            TableModel.setValueAt(ch.getDiachi(), i, 2);
            TableModel.setValueAt(ch.getSdt(), i, 3);
        }
        jTable_CuaHang.setModel(TableModel);

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable3 = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jtxtTenCuahHang = new javax.swing.JTextField();
        jtxtTenQuanLy = new javax.swing.JTextField();
        jtxtDiaChi = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jtxtSDT = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jtxtMaCuaHang = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jtxtXoa = new javax.swing.JButton();
        jbtnThemCuaHang = new javax.swing.JButton();
        jbtnCapNhat = new javax.swing.JButton();
        jButton_LamMoi = new javax.swing.JButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTable_CuaHang = new javax.swing.JTable();
        jbtnThoat = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(jTable2);

        jTable3.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane3.setViewportView(jTable3);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Thông Tin Quản Lý Chuỗi Cửa Hàng", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 14), java.awt.Color.blue)); // NOI18N

        jLabel1.setText("Tên Cửa Hàng (*)");

        jLabel2.setText("Tên Quản Lý (*)");

        jLabel3.setText("Địa Chỉ (*)");

        jTextField1.setText("jTextField1");

        jLabel4.setText("jLabel4");

        jLabel5.setText("Số điện thoại (*)");

        jLabel6.setText("Mã Cửa Hàng");

        jtxtMaCuaHang.setEditable(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel3))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jtxtSDT)
                            .addComponent(jtxtDiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jtxtMaCuaHang)
                            .addComponent(jtxtTenQuanLy)
                            .addComponent(jtxtTenCuahHang, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE))))
                .addContainerGap(84, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtxtMaCuaHang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jtxtTenCuahHang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jtxtTenQuanLy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jtxtDiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtxtSDT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addContainerGap(19, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Nhóm Chức Năng", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 14), java.awt.Color.blue)); // NOI18N

        jtxtXoa.setText("Xóa");
        jtxtXoa.setMaximumSize(new java.awt.Dimension(61, 23));
        jtxtXoa.setMinimumSize(new java.awt.Dimension(61, 23));
        jtxtXoa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtXoaActionPerformed(evt);
            }
        });

        jbtnThemCuaHang.setMnemonic('T');
        jbtnThemCuaHang.setText("Thêm ");
        jbtnThemCuaHang.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jbtnThemCuaHangMouseClicked(evt);
            }
        });
        jbtnThemCuaHang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnThemCuaHangActionPerformed(evt);
            }
        });

        jbtnCapNhat.setText("Cập Nhật");
        jbtnCapNhat.setMaximumSize(new java.awt.Dimension(61, 23));
        jbtnCapNhat.setMinimumSize(new java.awt.Dimension(61, 23));
        jbtnCapNhat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnCapNhatActionPerformed(evt);
            }
        });

        jButton_LamMoi.setText("Làm Mới");
        jButton_LamMoi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_LamMoiActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(31, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jButton_LamMoi, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jtxtXoa, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)
                    .addComponent(jbtnCapNhat, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)
                    .addComponent(jbtnThemCuaHang, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE))
                .addGap(38, 38, 38))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jbtnThemCuaHang, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jbtnCapNhat, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jtxtXoa, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton_LamMoi, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTable_CuaHang.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "ID", "Tên Cửa Hàng", "Tên Quản Lý", "Địa Chỉ", "SĐT"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jTable_CuaHang.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable_CuaHangMouseClicked(evt);
            }
        });
        jTable_CuaHang.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTable_CuaHangKeyPressed(evt);
            }
        });
        jScrollPane4.setViewportView(jTable_CuaHang);

        jbtnThoat.setText("Thoát");
        jbtnThoat.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jbtnThoatMouseClicked(evt);
            }
        });

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel8.setForeground(new java.awt.Color(0, 0, 102));
        jLabel8.setText("QUẢN LÝ CHUỖI CỬA HÀNG");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jbtnThoat, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(143, 143, 143)
                        .addComponent(jLabel8)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(29, Short.MAX_VALUE)
                .addComponent(jLabel8)
                .addGap(26, 26, 26)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(jbtnThoat, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(23, 23, 23))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jbtnThemCuaHangActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnThemCuaHangActionPerformed
// TODO add your handling code here:

    Cuahang ch = new Cuahang();
    ch.setTencuahang(this.jtxtMaCuaHang.getText());
    ch.setTencuahang(this.jtxtTenCuahHang.getText());
    ch.setChucuahang(this.jtxtTenQuanLy.getText());
    ch.setDiachi(this.jtxtDiaChi.getText());
    ch.setSdt(this.jtxtSDT.getText());

    boolean kq = CuaHangDAO.themCuaHang(ch);
    if (kq) {
        JOptionPane.showMessageDialog(this, "Thêm thành công !", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
    } else {
        JOptionPane.showMessageDialog(this, "Không thêm đươc !", "Thông báo", JOptionPane.WARNING_MESSAGE);
    }

    this._lch = CuaHangDAO.layDanhSachCuaHang();
    fillJTable(this._lch);
    this.jtxtMaCuaHang.setText("");
    this.jtxtTenCuahHang.setText("");
    this.jtxtTenQuanLy.setText("");
    this.jtxtDiaChi.setText("");
    this.jtxtSDT.setText("");
}//GEN-LAST:event_jbtnThemCuaHangActionPerformed

private void jtxtXoaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtxtXoaActionPerformed
// TODO add your handling code here:
    
    List<CuahangBophan> listCHBP = CuaHang_BoPhanDAO.layDanhSachCuaHangBoPhan(this._lch.get(_irow));
    List<Khosanpham> listKhoSP = KhoSanPhamDAO.layDanhSachKhoSanPham(this._lch.get(_irow));
    
    if(listCHBP != null || listKhoSP != null){
        JOptionPane.showMessageDialog(this, "Muốn xóa của hàng BĂT BUỘC phải xóa hết tất cả các dữ liệu liên quan đến cửa hàng này trước. \nBởi vì có rất nhiều dữ liệu liên quan và sự mất mát là khó lường !", "Thông báo", JOptionPane.WARNING_MESSAGE);
        return;
    }
    
    boolean kq = CuaHangDAO.xoaCuaHang(this._lch.get(_irow));
    if (kq) {
        JOptionPane.showMessageDialog(this, "Xóa thành công !", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
    } else {
        JOptionPane.showMessageDialog(this, "Xóa không được !", "Thông báo", JOptionPane.WARNING_MESSAGE);
    }

    this._lch = CuaHangDAO.layDanhSachCuaHang();
    fillJTable(this._lch);
    this.jtxtMaCuaHang.setText("");
    this.jtxtTenCuahHang.setText("");
    this.jtxtTenQuanLy.setText("");
    this.jtxtDiaChi.setText("");
    this.jtxtSDT.setText("");

}//GEN-LAST:event_jtxtXoaActionPerformed

private void jbtnThemCuaHangMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbtnThemCuaHangMouseClicked
// TODO add your handling code here:
    Cuahang ch = new Cuahang();
    ch.setTencuahang(jtxtTenCuahHang.getText());
    ch.setChucuahang(jtxtTenQuanLy.getText());
    ch.setDiachi(jtxtDiaChi.getText());
    ch.setSdt(jtxtSDT.getText());
    boolean kq = dao.CuaHangDAO.themCuaHang(ch);
    if (kq == true) {
        JOptionPane.showMessageDialog(this, "Thêm thành công");
        this.hienThiDanhSachCuaHang();
    } else {
        JOptionPane.showMessageDialog(this, "Không thêm được!");
    }
}//GEN-LAST:event_jbtnThemCuaHangMouseClicked

//tao table chua du lieu
    private void fillJTable(List<Cuahang> lch) {
        DefaultTableModel tableModel = new DefaultTableModel();
        tableModel.addColumn("Mã Cửa Hàng");
        tableModel.addColumn("Tên Cửa Hàng");
        tableModel.addColumn("Quản lý");
        tableModel.addColumn("Địa chỉ");
        tableModel.addColumn("Số điện thoại");
        this.jTable_CuaHang.setModel(tableModel);
        if (lch.size() > 0) {
            for (int i = 0; i < lch.size(); i++) {
                Vector vt = new Vector();
                vt.add(lch.get(i).getMacuahang());
                vt.add(lch.get(i).getTencuahang());
                vt.add(lch.get(i).getChucuahang());
                vt.add(lch.get(i).getDiachi());
                vt.add(lch.get(i).getSdt());

                tableModel.addRow(vt);
            }
        }
    }

private void jbtnThoatMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbtnThoatMouseClicked
// TODO add your handling code here:
    this.setVisible(false);
}//GEN-LAST:event_jbtnThoatMouseClicked

private void jbtnCapNhatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnCapNhatActionPerformed
// TODO add your handling code here:
    Cuahang ch = new Cuahang();
    ch.setMacuahang(Integer.valueOf(this.jtxtMaCuaHang.getText()));
    ch.setTencuahang(this.jtxtTenCuahHang.getText());
    ch.setChucuahang(this.jtxtTenQuanLy.getText());
    ch.setDiachi(this.jtxtDiaChi.getText());
    ch.setSdt(this.jtxtSDT.getText());

    boolean kq = CuaHangDAO.capnhatThongTinCuaHang(ch);
    if (kq) {
        JOptionPane.showMessageDialog(this, "Cập nhật thành công !", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
    } else {
        JOptionPane.showMessageDialog(this, "Cập nhật không được !", "Thông báo", JOptionPane.WARNING_MESSAGE);
    }

    this._lch = CuaHangDAO.layDanhSachCuaHang();
    fillJTable(this._lch);
    this.jtxtMaCuaHang.setText(this.jTable_CuaHang.getModel().getValueAt(_irow, 0).toString());
    this.jtxtTenCuahHang.setText(this.jTable_CuaHang.getModel().getValueAt(_irow, 1).toString());
    this.jtxtTenQuanLy.setText(this.jTable_CuaHang.getModel().getValueAt(_irow, 2).toString());
    this.jtxtDiaChi.setText(this.jTable_CuaHang.getModel().getValueAt(_irow, 3).toString());
    this.jtxtSDT.setText(this.jTable_CuaHang.getModel().getValueAt(_irow, 4).toString());

}//GEN-LAST:event_jbtnCapNhatActionPerformed

private void jTable_CuaHangMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable_CuaHangMouseClicked
// TODO add your handling code here:

    _irow = this.jTable_CuaHang.getSelectedRow();

    //lây du lieu tai dong dang chon trong table dua vao cac textfield
    this.jtxtMaCuaHang.setText(this.jTable_CuaHang.getModel().getValueAt(_irow, 0).toString());
    this.jtxtTenCuahHang.setText(this.jTable_CuaHang.getModel().getValueAt(_irow, 1).toString());
    this.jtxtTenQuanLy.setText(this.jTable_CuaHang.getModel().getValueAt(_irow, 2).toString());
    this.jtxtDiaChi.setText(this.jTable_CuaHang.getModel().getValueAt(_irow, 3).toString());
    this.jtxtSDT.setText(this.jTable_CuaHang.getModel().getValueAt(_irow, 4).toString());

}//GEN-LAST:event_jTable_CuaHangMouseClicked

private void jButton_LamMoiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_LamMoiActionPerformed
// TODO add your handling code here:
    fillJTable(this._lch);
    this.jtxtMaCuaHang.setText("");
    this.jtxtTenCuahHang.setText("");
    this.jtxtTenQuanLy.setText("");
    this.jtxtDiaChi.setText("");
    this.jtxtSDT.setText("");
}//GEN-LAST:event_jButton_LamMoiActionPerformed

    private void jTable_CuaHangKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable_CuaHangKeyPressed
        // TODO add your handling code here:
        _irow = this.jTable_CuaHang.getSelectedRow();
        int key = evt.getKeyCode();
        if (key == 40) {//nhan nut xuong
            _irow++;
        }
        if (key == 38) {//nhan nutlen
            _irow--;
        }
        //lây du lieu tai dong dang chon trong table dua vao cac textfield
        this.jtxtMaCuaHang.setText(this.jTable_CuaHang.getModel().getValueAt(_irow, 0).toString());
        this.jtxtTenCuahHang.setText(this.jTable_CuaHang.getModel().getValueAt(_irow, 1).toString());
        this.jtxtTenQuanLy.setText(this.jTable_CuaHang.getModel().getValueAt(_irow, 2).toString());
        this.jtxtDiaChi.setText(this.jTable_CuaHang.getModel().getValueAt(_irow, 3).toString());
        this.jtxtSDT.setText(this.jTable_CuaHang.getModel().getValueAt(_irow, 4).toString());
    }//GEN-LAST:event_jTable_CuaHangKeyPressed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(frmQuanLyChuoiCuaHang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(frmQuanLyChuoiCuaHang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(frmQuanLyChuoiCuaHang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(frmQuanLyChuoiCuaHang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new frmQuanLyChuoiCuaHang().setVisible(true);
            }
        });


    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_LamMoi;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTable jTable3;
    private javax.swing.JTable jTable_CuaHang;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JButton jbtnCapNhat;
    private javax.swing.JButton jbtnThemCuaHang;
    private javax.swing.JButton jbtnThoat;
    private javax.swing.JTextField jtxtDiaChi;
    private javax.swing.JTextField jtxtMaCuaHang;
    private javax.swing.JTextField jtxtSDT;
    private javax.swing.JTextField jtxtTenCuahHang;
    private javax.swing.JTextField jtxtTenQuanLy;
    private javax.swing.JButton jtxtXoa;
    // End of variables declaration//GEN-END:variables
}
